'use strict';

module.exports = app => {
  const {
    INTEGER,
    STRING,
    FLOAT,
    DATE,
  } = app.Sequelize;
  const TbOrder = app.model.define('tb_order', {
    id: {
      type: INTEGER,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
      comment: '序号',
    },
    uid: {
      type: INTEGER,
      comment: '用户id',
    },
    pid: {
      type: INTEGER,
      comment: '商品id'
    },
    ordernumber: {
      type: STRING,
      comment: '订单号',
    },
    orderimg: {
      type: STRING,
      comment: '订单商品图片',
    },
    title: {
      type: STRING,
      comment: '订单商品标题',
    },
    price: {
      type: FLOAT,
      comment: '订单商品价格',
    },
    num: {
      type: INTEGER,
      comment: '订单商品数量',
    },
    totalprice: {
      type: FLOAT,
      comment: '订单商品总价格',
    },
    car: {
      type: INTEGER(2),
      comment: '是否在购物车',
    },
    carcheck: {
      type: INTEGER(3),
      comment: '是否选择'
    },
    freight: {
      type: FLOAT,
      comment: '运费',
    },
    consignee: {
      type: STRING,
      comment: '收货人',
    },
    distribution: {
      type: STRING,
      comment: '配送店铺',
    },
    address: {
      type: STRING,
      comment: '地址',
    },
    tel: {
      type: STRING,
      comment: '收货人电话',
    },
    integral: {
      type: STRING,
      comment: '积分',
    },
    invoiceinfo: {
      type: STRING,
      comment: '发票信息',
    },
    state: {
      type: INTEGER(4),
      comment: '订单的状态, 0 - 表示未付款， 1 - 表示待发货， 2 - 表示已收货， 3 - 表示已评价， 4 - 表示已取消 ',
    },
    createdDate: {
      type: DATE,
      comment: '订单创建时间',
      field: 'createdDate',
    },
  }, {
    freezeTableName: true,
    timestamps: false, // 去除createAt updateAt
  });
  TbOrder.associate = function () {
    app.model.TbOrder.belongsTo(app.model.User, {
      foreignKey: 'uid',
      targetKey: 'id',
    });
  };
  return TbOrder;
};